using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Repository;
using System.Linq;
using ZR.Service.IService.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model;

namespace ZR.Service.Service.ProductionControl
{
    /// <summary>
    /// 设备工位绑定关系表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IDeviceBindingService), ServiceLifetime = LifeTime.Transient)]
    public class DeviceBindingService : BaseService<DeviceBinding>, IDeviceBindingService
    {
        /// <summary>
        /// 查询设备工位绑定关系表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<DeviceBindingDto> GetList(DeviceBindingQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<DeviceBinding, DeviceBindingDto>(parm);

            return response;
        }


        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public DeviceBinding GetInfo(int Id)
        {
            var response = Queryable()
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加设备工位绑定关系表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DeviceBinding AddDeviceBinding(DeviceBinding model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改设备工位绑定关系表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateDeviceBinding(DeviceBinding model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<DeviceBinding> QueryExp(DeviceBindingQueryDto parm)
        {
            var predicate = Expressionable.Create<DeviceBinding>();

            return predicate;
        }
    }
}